package com.keur.money.utils.dialog

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.keur.money.R
import com.keur.money.databinding.DialogPermissionTipsBinding
import com.keur.money.http.HttpHelper
import com.keur.money.utils.event.KeurEventType

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/7/8 15:50
 * @Annotation：权限提示dialog
 */
class PermissionTipsDialog: ProDialog {

    private lateinit var binding: DialogPermissionTipsBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    override fun initWindow() {
        val params = window?.attributes
        params?.width = WindowManager.LayoutParams.MATCH_PARENT
        params?.height = WindowManager.LayoutParams.WRAP_CONTENT
        window?.attributes = params
        window?.setWindowAnimations(R.style.picker_view_slide_anim) //修改动画样式
        window?.setGravity(Gravity.BOTTOM)
    }

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context?, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogPermissionTipsBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(R.id.btnOk) //两个按钮 左侧按钮
        setOnClickListener(R.id.btnCancel) //两个按钮 又侧按钮
        setOnClickListener(R.id.parentLayout)
        setOnClickListener(R.id.contentLayout)
    }

    override fun initData() {
    }

    override fun onViewClick(v: View?) {
        if (v?.id == R.id.contentLayout){
            return
        }
        dismiss()
        if(mCallback != null){
            mCallback?.onClick(v)
        }
    }

    /**
     * 设置提示图标
     */
    fun setTipsIconResource(resId: Int){
        binding.ivIcon.setImageResource(resId)
    }

    /**
     * 设置提示title
     */
    fun setTipsTitle(title: String){
        binding.tvTipsTitle.text = title
    }

    /**
     * 设置提示语
     */
    fun setTips(tips: String){
        binding.tvTips.text = tips
    }

    /**
     * 显示取消按钮
     */
    fun showSibBtnCancel(){
        binding.btnCancel.visibility = View.VISIBLE
    }

    /**
     * 隐藏取消按钮
     */
    fun hideSibBtnCancel(){
        binding.btnCancel.visibility = View.GONE
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        HttpHelper.addKeurEventAction(KeurEventType.DIALOG.KEUR_DIALOG_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        HttpHelper.addKeurEventAction(KeurEventType.DIALOG.KEUR_DIALOG_TIPS_DISMISS,eventRemark)
    }
}